<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        margin-left: 300px;
        width: 600px;
        display: flex;
        flex-wrap: nowrap;
        position: relative;
        border: solid;
        overflow: hidden;
      }
      #box ul {
        display: flex;
        flex-wrap: nowrap;
        list-style: none;
        margin: 0;
        padding: 0;
        background-color: rgba(167, 228, 237, 0.611);
        transition: 200ms;
      }
      #box ul li {
        width: 200px;
      }
      #box ul li img {
        width: 100%;
      }

      #box .left,
      #box .right {
        width: 50px;
        height: 50px;
        position: absolute;
        background-color: rgba(0, 0, 0, 0.5);
        color: white;
        top: calc(50% - 25px);
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 1.5rem;
        cursor: pointer;
      }
      #box .left:hover,
      #box .right:hover {
        background-color: rgba(0, 0, 0, 0.8);
        font-size: 1.8rem;
      }

      #box .right {
        right: 0;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div class="left">←</div>
      <ul>
        <li><img src="./imgs/1.png" alt="" /></li>
        <li><img src="./imgs/2.png" alt="" /></li>
        <li><img src="./imgs/3.png" alt="" /></li>
        <li><img src="./imgs/4.png" alt="" /></li>
        <li><img src="./imgs/6.png" alt="" /></li>
        <li><img src="./imgs/7.png" alt="" /></li>
        <li><img src="./imgs/8.png" alt="" /></li>
        <li><img src="./imgs/9.png" alt="" /></li>
        <li><img src="./imgs/10.png" alt="" /></li>
      </ul>
      <div class="right">→</div>
    </div>
    <script>
      const ul = document.querySelector("#box ul");
      const lis = document.querySelectorAll("#box ul li");

      let pos = 0;
      document.querySelector("#box .left").onclick = function () {
        pos += 200 * 3;
        // if (pos > 0) {
        //   pos = 0;
        // }
        pos = Math.min(pos, 0);
        ul.style.marginLeft = pos + "px";
      };
      document.querySelector("#box .right").onclick = function () {
        pos -= 200 * 3;
        // if (pos + lis.length * 200 <= 200 * 3) {
        //   pos = -lis.length * 200 + 200 * 3;
        // }
        pos = Math.max(pos, -lis.length * 200 + 200 * 3);
        ul.style.marginLeft = pos + "px";
      };
    </script>
  </body>
</html>
